﻿using System;
using UnityEngine;
using System.IO;
using System.Collections.Generic;

[Serializable]
public class GameData {

    public List<int> selectedSkillIds = new List<int>();
    public List<int> itemIds = new List<int>();
    public string ToJson()
    {
        
        return JsonUtility.ToJson(this);
    }

    public void saveToLocal()
    {
        
        selectedSkillIds = DataManager.GetInstance().selectedSkillIds;
        itemIds = DataManager.GetInstance().itemIds;
        //如果本地没有对应的json 文件，重新创建
        if (!File.Exists(JsonPath()))
        {
            File.Create(JsonPath()).Dispose();
        }
        File.WriteAllText(JsonPath(), JsonUtility.ToJson(this));
        Debug.Log("保存成功");
    }

    //保存json文件路径
    string JsonPath()
    {
        Debug.Log(Path.Combine(Application.persistentDataPath, "GameData.json"));
        return Path.Combine(Application.persistentDataPath, "GameData.json");
       // return Application.streamingAssetsPath + "/GameData.json";
    }


}

